package org.projectwithoutname.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.projectwithoutname.ui.util.MediaPlayerUtil;
import org.projectwithoutname.ui.view.EpisodesView;
import org.projectwithoutname.ui.view.InformationView;


public class PlayHandler extends AbstractHandler implements IHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		IWorkbenchPage page = window.getActivePage();
		InformationView view = (InformationView) page.findView(InformationView.ID);
		EpisodesView episodesView = (EpisodesView) page.findView(EpisodesView.ID);
		String fileName = episodesView.getFilePath();
		
//		hide background image
		if ((view.getImageLayout() != null) && (view.getVideoLayout() == null)){
			view.setImageLayout(null);
			view.showVideoLayout();
		}

//		show player and run a video stream
		MediaPlayerUtil player = view.getMediaPlayer();
		player.run(fileName);
		
		return null;
	}

}
